/*
 * Copyright (c) 2024 vitasystems GmbH
 *
 * This file is part of project EHRbase Migration Tool
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ehrbase.migration.importer.v4.jooq.pg.tables;

import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import org.ehrbase.migration.importer.v4.jooq.pg.Keys;
import org.ehrbase.migration.importer.v4.jooq.pg.tables.records.EhrStatusVersionHistoryRecord;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Function8;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Records;
import org.jooq.Row8;
import org.jooq.Schema;
import org.jooq.SelectField;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions;
import org.jooq.UniqueKey;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({"all", "unchecked", "rawtypes", "this-escape"})
public class EhrStatusVersionHistory extends TableImpl<EhrStatusVersionHistoryRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of <code>ehr.ehr_status_version_history</code>
     */
    public static final EhrStatusVersionHistory EHR_STATUS_VERSION_HISTORY = new EhrStatusVersionHistory();

    /**
     * The class holding records for this type
     */
    @Override
    public Class<EhrStatusVersionHistoryRecord> getRecordType() {
        return EhrStatusVersionHistoryRecord.class;
    }

    /**
     * The column <code>ehr.ehr_status_version_history.vo_id</code>.
     */
    public final TableField<EhrStatusVersionHistoryRecord, UUID> VO_ID =
            createField(DSL.name("vo_id"), SQLDataType.UUID.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_status_version_history.ehr_id</code>.
     */
    public final TableField<EhrStatusVersionHistoryRecord, UUID> EHR_ID =
            createField(DSL.name("ehr_id"), SQLDataType.UUID.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_status_version_history.contribution_id</code>.
     */
    public final TableField<EhrStatusVersionHistoryRecord, UUID> CONTRIBUTION_ID =
            createField(DSL.name("contribution_id"), SQLDataType.UUID.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_status_version_history.audit_id</code>.
     */
    public final TableField<EhrStatusVersionHistoryRecord, UUID> AUDIT_ID =
            createField(DSL.name("audit_id"), SQLDataType.UUID.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_status_version_history.sys_version</code>.
     */
    public final TableField<EhrStatusVersionHistoryRecord, Integer> SYS_VERSION =
            createField(DSL.name("sys_version"), SQLDataType.INTEGER.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_status_version_history.sys_period_lower</code>.
     */
    public final TableField<EhrStatusVersionHistoryRecord, OffsetDateTime> SYS_PERIOD_LOWER = createField(
            DSL.name("sys_period_lower"), SQLDataType.TIMESTAMPWITHTIMEZONE(6).nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_status_version_history.sys_period_upper</code>.
     */
    public final TableField<EhrStatusVersionHistoryRecord, OffsetDateTime> SYS_PERIOD_UPPER =
            createField(DSL.name("sys_period_upper"), SQLDataType.TIMESTAMPWITHTIMEZONE(6), this, "");

    /**
     * The column <code>ehr.ehr_status_version_history.sys_deleted</code>.
     */
    public final TableField<EhrStatusVersionHistoryRecord, Boolean> SYS_DELETED =
            createField(DSL.name("sys_deleted"), SQLDataType.BOOLEAN.nullable(false), this, "");

    private EhrStatusVersionHistory(Name alias, Table<EhrStatusVersionHistoryRecord> aliased) {
        this(alias, aliased, null);
    }

    private EhrStatusVersionHistory(Name alias, Table<EhrStatusVersionHistoryRecord> aliased, Field<?>[] parameters) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table());
    }

    /**
     * Create an aliased <code>ehr.ehr_status_version_history</code> table
     * reference
     */
    public EhrStatusVersionHistory(String alias) {
        this(DSL.name(alias), EHR_STATUS_VERSION_HISTORY);
    }

    /**
     * Create an aliased <code>ehr.ehr_status_version_history</code> table
     * reference
     */
    public EhrStatusVersionHistory(Name alias) {
        this(alias, EHR_STATUS_VERSION_HISTORY);
    }

    /**
     * Create a <code>ehr.ehr_status_version_history</code> table reference
     */
    public EhrStatusVersionHistory() {
        this(DSL.name("ehr_status_version_history"), null);
    }

    public <O extends Record> EhrStatusVersionHistory(
            Table<O> child, ForeignKey<O, EhrStatusVersionHistoryRecord> key) {
        super(child, key, EHR_STATUS_VERSION_HISTORY);
    }

    @Override
    public Schema getSchema() {
        return aliased() ? null : org.ehrbase.migration.importer.v4.jooq.pg.Ehr.EHR;
    }

    @Override
    public UniqueKey<EhrStatusVersionHistoryRecord> getPrimaryKey() {
        return Keys.EHR_STATUS_VERSION_HISTORY_PKEY;
    }

    @Override
    public List<ForeignKey<EhrStatusVersionHistoryRecord, ?>> getReferences() {
        return Arrays.asList(
                Keys.EHR_STATUS_VERSION_HISTORY__EHR_STATUS_VERSION_HISTORY_EHR_ID_FKEY,
                Keys.EHR_STATUS_VERSION_HISTORY__EHR_STATUS_VERSION_HISTORY_CONTRIBUTION_ID_FKEY,
                Keys.EHR_STATUS_VERSION_HISTORY__EHR_STATUS_VERSION_HISTORY_AUDIT_ID_FKEY);
    }

    private transient org.ehrbase.migration.importer.v4.jooq.pg.tables.Ehr _ehr;
    private transient Contribution _contribution;
    private transient AuditDetails _auditDetails;

    /**
     * Get the implicit join path to the <code>ehr.ehr</code> table.
     */
    public org.ehrbase.migration.importer.v4.jooq.pg.tables.Ehr ehr() {
        if (_ehr == null)
            _ehr = new org.ehrbase.migration.importer.v4.jooq.pg.tables.Ehr(
                    this, Keys.EHR_STATUS_VERSION_HISTORY__EHR_STATUS_VERSION_HISTORY_EHR_ID_FKEY);

        return _ehr;
    }

    /**
     * Get the implicit join path to the <code>ehr.contribution</code> table.
     */
    public Contribution contribution() {
        if (_contribution == null)
            _contribution = new Contribution(
                    this, Keys.EHR_STATUS_VERSION_HISTORY__EHR_STATUS_VERSION_HISTORY_CONTRIBUTION_ID_FKEY);

        return _contribution;
    }

    /**
     * Get the implicit join path to the <code>ehr.audit_details</code> table.
     */
    public AuditDetails auditDetails() {
        if (_auditDetails == null)
            _auditDetails =
                    new AuditDetails(this, Keys.EHR_STATUS_VERSION_HISTORY__EHR_STATUS_VERSION_HISTORY_AUDIT_ID_FKEY);

        return _auditDetails;
    }

    @Override
    public EhrStatusVersionHistory as(String alias) {
        return new EhrStatusVersionHistory(DSL.name(alias), this);
    }

    @Override
    public EhrStatusVersionHistory as(Name alias) {
        return new EhrStatusVersionHistory(alias, this);
    }

    @Override
    public EhrStatusVersionHistory as(Table<?> alias) {
        return new EhrStatusVersionHistory(alias.getQualifiedName(), this);
    }

    /**
     * Rename this table
     */
    @Override
    public EhrStatusVersionHistory rename(String name) {
        return new EhrStatusVersionHistory(DSL.name(name), null);
    }

    /**
     * Rename this table
     */
    @Override
    public EhrStatusVersionHistory rename(Name name) {
        return new EhrStatusVersionHistory(name, null);
    }

    /**
     * Rename this table
     */
    @Override
    public EhrStatusVersionHistory rename(Table<?> name) {
        return new EhrStatusVersionHistory(name.getQualifiedName(), null);
    }

    // -------------------------------------------------------------------------
    // Row8 type methods
    // -------------------------------------------------------------------------

    @Override
    public Row8<UUID, UUID, UUID, UUID, Integer, OffsetDateTime, OffsetDateTime, Boolean> fieldsRow() {
        return (Row8) super.fieldsRow();
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Function)}.
     */
    public <U> SelectField<U> mapping(
            Function8<
                            ? super UUID,
                            ? super UUID,
                            ? super UUID,
                            ? super UUID,
                            ? super Integer,
                            ? super OffsetDateTime,
                            ? super OffsetDateTime,
                            ? super Boolean,
                            ? extends U>
                    from) {
        return convertFrom(Records.mapping(from));
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Class,
     * Function)}.
     */
    public <U> SelectField<U> mapping(
            Class<U> toType,
            Function8<
                            ? super UUID,
                            ? super UUID,
                            ? super UUID,
                            ? super UUID,
                            ? super Integer,
                            ? super OffsetDateTime,
                            ? super OffsetDateTime,
                            ? super Boolean,
                            ? extends U>
                    from) {
        return convertFrom(toType, Records.mapping(from));
    }
}
